package com.reportgear.report.model.script;

// $ANTLR 3.2 Sep 23, 2009 12:02:23 D:\\antlr\\Expr.g 2010-01-27 21:34:16

import java.util.ArrayList;
import java.util.List;

import org.antlr.runtime.BitSet;
import org.antlr.runtime.NoViableAltException;
import org.antlr.runtime.Parser;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;

public class ExprParser extends Parser {
	public static final String[] tokenNames = new String[] { "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PLUS", "SUB",
			"FUNCNAME", "WS", "StringLiteral", "NumberLiteral", "VAR", "COLUMNROW", "Digit", "DigitNoZero", "HexDigit",
			"UnicodeEscape", "OctalEscape", "EscapeSequence", "BooleanLiteral", "'*'", "'/'", "'('", "')'", "','" };
	public static final int T__23 = 23;
	public static final int NumberLiteral = 9;
	public static final int T__22 = 22;
	public static final int T__21 = 21;
	public static final int T__20 = 20;
	public static final int SUB = 5;
	public static final int Digit = 12;
	public static final int EOF = -1;
	public static final int HexDigit = 14;
	public static final int StringLiteral = 8;
	public static final int T__19 = 19;
	public static final int DigitNoZero = 13;
	public static final int WS = 7;
	public static final int COLUMNROW = 11;
	public static final int UnicodeEscape = 15;
	public static final int PLUS = 4;
	public static final int VAR = 10;
	public static final int FUNCNAME = 6;
	public static final int EscapeSequence = 17;
	public static final int OctalEscape = 16;
	public static final int BooleanLiteral = 18;

	// delegates
	// delegators

	public ExprParser(TokenStream input) {
		this(input, new RecognizerSharedState());
	}

	public ExprParser(TokenStream input, RecognizerSharedState state) {
		super(input, state);

	}

	public String[] getTokenNames() {
		return ExprParser.tokenNames;
	}

	public String getGrammarFileName() {
		return "D:\\antlr\\Expr.g";
	}

	private ScriptContext scriptContext = ScriptContext.INSTANCE;

	// $ANTLR start "expr"
	// D:\\antlr\\Expr.g:17:1: expr returns [Object value] : ( (e= multExpr (
	// PLUS e= multExpr | '-' e= multExpr | PLUS e= strValue )* ) | (e= strValue
	// ( PLUS e= multExpr | PLUS e= strValue )* ) );
	public final Object expr() throws RecognitionException {
		Object value = null;

		Object e = null;

		try {
			// D:\\antlr\\Expr.g:18:5: ( (e= multExpr ( PLUS e= multExpr | '-'
			// e= multExpr | PLUS e= strValue )* ) | (e= strValue ( PLUS e=
			// multExpr | PLUS e= strValue )* ) )
			int alt3 = 2;
			int LA3_0 = input.LA(1);

			if ((LA3_0 == FUNCNAME || (LA3_0 >= NumberLiteral && LA3_0 <= COLUMNROW) || LA3_0 == 21)) {
				alt3 = 1;
			} else if ((LA3_0 == StringLiteral)) {
				alt3 = 2;
			} else {
				NoViableAltException nvae = new NoViableAltException("", 3, 0, input);

				throw nvae;
			}
			switch (alt3) {
			case 1:
				// D:\\antlr\\Expr.g:19:6: (e= multExpr ( PLUS e= multExpr | '-'
				// e= multExpr | PLUS e= strValue )* )
			{
				// D:\\antlr\\Expr.g:19:6: (e= multExpr ( PLUS e= multExpr | '-'
				// e= multExpr | PLUS e= strValue )* )
				// D:\\antlr\\Expr.g:20:7: e= multExpr ( PLUS e= multExpr | '-'
				// e= multExpr | PLUS e= strValue )*
				{
					pushFollow(FOLLOW_multExpr_in_expr68);
					e = multExpr();

					state._fsp--;

					value = e;
					// D:\\antlr\\Expr.g:21:10: ( PLUS e= multExpr | '-' e=
					// multExpr | PLUS e= strValue )*
					loop1: do {
						int alt1 = 4;
						int LA1_0 = input.LA(1);

						if ((LA1_0 == PLUS)) {
							int LA1_2 = input.LA(2);

							if ((LA1_2 == FUNCNAME || (LA1_2 >= NumberLiteral && LA1_2 <= COLUMNROW) || LA1_2 == 21)) {
								alt1 = 1;
							} else if ((LA1_2 == StringLiteral)) {
								alt1 = 3;
							}

						} else if ((LA1_0 == SUB)) {
							alt1 = 2;
						}

						switch (alt1) {
						case 1:
							// D:\\antlr\\Expr.g:21:14: PLUS e= multExpr
						{
							match(input, PLUS, FOLLOW_PLUS_in_expr85);
							pushFollow(FOLLOW_multExpr_in_expr89);
							e = multExpr();

							state._fsp--;

							value = ObjectUtils.add(value, e);

						}
							break;
						case 2:
							// D:\\antlr\\Expr.g:24:14: '-' e= multExpr
						{
							match(input, SUB, FOLLOW_SUB_in_expr106);
							pushFollow(FOLLOW_multExpr_in_expr110);
							e = multExpr();

							state._fsp--;

							value = ObjectUtils.sub(value, e);

						}
							break;
						case 3:
							// D:\\antlr\\Expr.g:27:12: PLUS e= strValue
						{
							match(input, PLUS, FOLLOW_PLUS_in_expr125);
							pushFollow(FOLLOW_strValue_in_expr130);
							e = strValue();

							state._fsp--;

							value = String.valueOf(value) + e;

						}
							break;

						default:
							break loop1;
						}
					} while (true);

				}

			}
				break;
			case 2:
				// D:\\antlr\\Expr.g:33:9: (e= strValue ( PLUS e= multExpr |
				// PLUS e= strValue )* )
			{
				// D:\\antlr\\Expr.g:33:9: (e= strValue ( PLUS e= multExpr |
				// PLUS e= strValue )* )
				// D:\\antlr\\Expr.g:34:10: e= strValue ( PLUS e= multExpr |
				// PLUS e= strValue )*
				{
					pushFollow(FOLLOW_strValue_in_expr186);
					e = strValue();

					state._fsp--;

					value = e;
					// D:\\antlr\\Expr.g:35:10: ( PLUS e= multExpr | PLUS e=
					// strValue )*
					loop2: do {
						int alt2 = 3;
						int LA2_0 = input.LA(1);

						if ((LA2_0 == PLUS)) {
							int LA2_2 = input.LA(2);

							if ((LA2_2 == FUNCNAME || (LA2_2 >= NumberLiteral && LA2_2 <= COLUMNROW) || LA2_2 == 21)) {
								alt2 = 1;
							} else if ((LA2_2 == StringLiteral)) {
								alt2 = 2;
							}

						}

						switch (alt2) {
						case 1:
							// D:\\antlr\\Expr.g:36:11: PLUS e= multExpr
						{
							match(input, PLUS, FOLLOW_PLUS_in_expr210);
							pushFollow(FOLLOW_multExpr_in_expr214);
							e = multExpr();

							state._fsp--;

							value = value + String.valueOf(e);

						}
							break;
						case 2:
							// D:\\antlr\\Expr.g:40:11: PLUS e= strValue
						{
							match(input, PLUS, FOLLOW_PLUS_in_expr239);
							pushFollow(FOLLOW_strValue_in_expr243);
							e = strValue();

							state._fsp--;

							value = value + String.valueOf(e);

						}
							break;

						default:
							break loop2;
						}
					} while (true);

				}

			}
				break;

			}
		} catch (RecognitionException re) {
			reportError(re);
			recover(input, re);
		} finally {
		}
		return value;
	}

	// $ANTLR end "expr"

	// $ANTLR start "multExpr"
	// D:\\antlr\\Expr.g:47:1: multExpr returns [Object value] : e= atom ( '*'
	// e= atom | '/' e= atom )* ;
	public final Object multExpr() throws RecognitionException {
		Object value = null;

		Object e = null;

		try {
			// D:\\antlr\\Expr.g:48:5: (e= atom ( '*' e= atom | '/' e= atom )* )
			// D:\\antlr\\Expr.g:48:9: e= atom ( '*' e= atom | '/' e= atom )*
			{
				pushFollow(FOLLOW_atom_in_multExpr293);
				e = atom();

				state._fsp--;

				value = e;
				// D:\\antlr\\Expr.g:49:6: ( '*' e= atom | '/' e= atom )*
				loop4: do {
					int alt4 = 3;
					int LA4_0 = input.LA(1);

					if ((LA4_0 == 19)) {
						alt4 = 1;
					} else if ((LA4_0 == 20)) {
						alt4 = 2;
					}

					switch (alt4) {
					case 1:
						// D:\\antlr\\Expr.g:50:7: '*' e= atom
					{
						match(input, 19, FOLLOW_19_in_multExpr312);
						pushFollow(FOLLOW_atom_in_multExpr316);
						e = atom();

						state._fsp--;

						value = ObjectUtils.mult(value, e);

					}
						break;
					case 2:
						// D:\\antlr\\Expr.g:53:8: '/' e= atom
					{
						match(input, 20, FOLLOW_20_in_multExpr327);
						pushFollow(FOLLOW_atom_in_multExpr331);
						e = atom();

						state._fsp--;

						value = ObjectUtils.div(value, e);

					}
						break;

					default:
						break loop4;
					}
				} while (true);

			}

		} catch (RecognitionException re) {
			reportError(re);
			recover(input, re);
		} finally {
		}
		return value;
	}

	// $ANTLR end "multExpr"

	// $ANTLR start "func"
	// D:\\antlr\\Expr.g:60:1: func returns [Object value] : FUNCNAME '(' ( ( WS
	// )* | e= args ) ')' ;
	public final Object func() throws RecognitionException {
		Object value = null;

		Token FUNCNAME1 = null;
		List<Object> e = null;

		try {
			// D:\\antlr\\Expr.g:61:2: ( FUNCNAME '(' ( ( WS )* | e= args ) ')'
			// )
			// D:\\antlr\\Expr.g:61:5: FUNCNAME '(' ( ( WS )* | e= args ) ')'
			{
				FUNCNAME1 = (Token) match(input, FUNCNAME, FOLLOW_FUNCNAME_in_func362);
				match(input, 21, FOLLOW_21_in_func364);
				// D:\\antlr\\Expr.g:62:3: ( ( WS )* | e= args )
				int alt6 = 2;
				int LA6_0 = input.LA(1);

				if ((LA6_0 == WS || LA6_0 == 22)) {
					alt6 = 1;
				} else if ((LA6_0 == FUNCNAME || (LA6_0 >= StringLiteral && LA6_0 <= COLUMNROW) || LA6_0 == 21)) {
					alt6 = 2;
				} else {
					NoViableAltException nvae = new NoViableAltException("", 6, 0, input);

					throw nvae;
				}
				switch (alt6) {
				case 1:
					// D:\\antlr\\Expr.g:62:5: ( WS )*
				{
					// D:\\antlr\\Expr.g:62:5: ( WS )*
					loop5: do {
						int alt5 = 2;
						int LA5_0 = input.LA(1);

						if ((LA5_0 == WS)) {
							alt5 = 1;
						}

						switch (alt5) {
						case 1:
							// D:\\antlr\\Expr.g:62:5: WS
						{
							match(input, WS, FOLLOW_WS_in_func371);

						}
							break;

						default:
							break loop5;
						}
					} while (true);

					value = scriptContext.getFuncValue((FUNCNAME1 != null ? FUNCNAME1.getText() : null), null);

				}
					break;
				case 2:
					// D:\\antlr\\Expr.g:64:4: e= args
				{
					pushFollow(FOLLOW_args_in_func385);
					e = args();

					state._fsp--;

					value = scriptContext.getFuncValue((FUNCNAME1 != null ? FUNCNAME1.getText() : null), e);

				}
					break;

				}

				match(input, 22, FOLLOW_22_in_func394);

			}

		} catch (RecognitionException re) {
			reportError(re);
			recover(input, re);
		} finally {
		}
		return value;
	}

	// $ANTLR end "func"

	// $ANTLR start "args"
	// D:\\antlr\\Expr.g:70:1: args returns [List<Object> value] : (e= expr ) (
	// ',' (e= strQuoted | e= expr ) )* ;
	public final List<Object> args() throws RecognitionException {
		List<Object> value = null;

		Object e = null;

		value = new ArrayList<Object>();

		try {
			// D:\\antlr\\Expr.g:74:6: ( (e= expr ) ( ',' (e= strQuoted | e=
			// expr ) )* )
			// D:\\antlr\\Expr.g:74:8: (e= expr ) ( ',' (e= strQuoted | e= expr
			// ) )*
			{
				// D:\\antlr\\Expr.g:74:8: (e= expr )
				// D:\\antlr\\Expr.g:74:9: e= expr
				{
					pushFollow(FOLLOW_expr_in_args423);
					e = expr();

					state._fsp--;

					value.add(e);

				}

				// D:\\antlr\\Expr.g:75:7: ( ',' (e= strQuoted | e= expr ) )*
				loop8: do {
					int alt8 = 2;
					int LA8_0 = input.LA(1);

					if ((LA8_0 == 23)) {
						alt8 = 1;
					}

					switch (alt8) {
					case 1:
						// D:\\antlr\\Expr.g:76:8: ',' (e= strQuoted | e= expr )
					{
						match(input, 23, FOLLOW_23_in_args443);
						// D:\\antlr\\Expr.g:76:12: (e= strQuoted | e= expr )
						int alt7 = 2;
						int LA7_0 = input.LA(1);

						if ((LA7_0 == StringLiteral)) {
							alt7 = 1;
						} else if ((LA7_0 == FUNCNAME || (LA7_0 >= NumberLiteral && LA7_0 <= COLUMNROW) || LA7_0 == 21)) {
							alt7 = 2;
						} else {
							NoViableAltException nvae = new NoViableAltException("", 7, 0, input);

							throw nvae;
						}
						switch (alt7) {
						case 1:
							// D:\\antlr\\Expr.g:77:9: e= strQuoted
						{
							pushFollow(FOLLOW_strQuoted_in_args457);
							e = strQuoted();

							state._fsp--;

							value.add(e);

						}
							break;
						case 2:
							// D:\\antlr\\Expr.g:79:9: e= expr
						{
							pushFollow(FOLLOW_expr_in_args480);
							e = expr();

							state._fsp--;

							value.add(e);

						}
							break;

						}

					}
						break;

					default:
						break loop8;
					}
				} while (true);

			}

		} catch (RecognitionException re) {
			reportError(re);
			recover(input, re);
		} finally {
		}
		return value;
	}

	// $ANTLR end "args"

	// $ANTLR start "strValue"
	// D:\\antlr\\Expr.g:84:1: strValue returns [Object value] : StringLiteral ;
	public final Object strValue() throws RecognitionException {
		Object value = null;

		Token StringLiteral2 = null;

		try {
			// D:\\antlr\\Expr.g:85:2: ( StringLiteral )
			// D:\\antlr\\Expr.g:85:8: StringLiteral
			{
				StringLiteral2 = (Token) match(input, StringLiteral, FOLLOW_StringLiteral_in_strValue533);

				String v = (StringLiteral2 != null ? StringLiteral2.getText() : null);
				value = v.substring(1, v.length() - 1);

			}

		} catch (RecognitionException re) {
			reportError(re);
			recover(input, re);
		} finally {
		}
		return value;
	}

	// $ANTLR end "strValue"

	// $ANTLR start "strQuoted"
	// D:\\antlr\\Expr.g:91:1: strQuoted returns [Object value] : StringLiteral
	// ;
	public final Object strQuoted() throws RecognitionException {
		Object value = null;

		Token StringLiteral3 = null;

		try {
			// D:\\antlr\\Expr.g:92:2: ( StringLiteral )
			// D:\\antlr\\Expr.g:92:8: StringLiteral
			{
				StringLiteral3 = (Token) match(input, StringLiteral, FOLLOW_StringLiteral_in_strQuoted555);

				value = (StringLiteral3 != null ? StringLiteral3.getText() : null);

			}

		} catch (RecognitionException re) {
			reportError(re);
			recover(input, re);
		} finally {
		}
		return value;
	}

	// $ANTLR end "strQuoted"

	// $ANTLR start "atom"
	// D:\\antlr\\Expr.g:97:1: atom returns [Object value] : ( NumberLiteral |
	// VAR | func | COLUMNROW | '(' expr ')' );
	public final Object atom() throws RecognitionException {
		Object value = null;

		Token NumberLiteral4 = null;
		Token VAR5 = null;
		Token COLUMNROW7 = null;
		Object func6 = null;

		Object expr8 = null;

		try {
			// D:\\antlr\\Expr.g:98:6: ( NumberLiteral | VAR | func | COLUMNROW
			// | '(' expr ')' )
			int alt9 = 5;
			switch (input.LA(1)) {
			case NumberLiteral: {
				alt9 = 1;
			}
				break;
			case VAR: {
				alt9 = 2;
			}
				break;
			case FUNCNAME: {
				alt9 = 3;
			}
				break;
			case COLUMNROW: {
				alt9 = 4;
			}
				break;
			case 21: {
				alt9 = 5;
			}
				break;
			default:
				NoViableAltException nvae = new NoViableAltException("", 9, 0, input);

				throw nvae;
			}

			switch (alt9) {
			case 1:
				// D:\\antlr\\Expr.g:98:11: NumberLiteral
			{
				NumberLiteral4 = (Token) match(input, NumberLiteral, FOLLOW_NumberLiteral_in_atom584);
				value = (NumberLiteral4 != null ? NumberLiteral4.getText() : null);

			}
				break;
			case 2:
				// D:\\antlr\\Expr.g:99:10: VAR
			{
				VAR5 = (Token) match(input, VAR, FOLLOW_VAR_in_atom597);
				value = scriptContext.getVariable((VAR5 != null ? VAR5.getText() : null));

			}
				break;
			case 3:
				// D:\\antlr\\Expr.g:100:11: func
			{
				pushFollow(FOLLOW_func_in_atom611);
				func6 = func();

				state._fsp--;

				value = func6;

			}
				break;
			case 4:
				// D:\\antlr\\Expr.g:101:11: COLUMNROW
			{
				COLUMNROW7 = (Token) match(input, COLUMNROW, FOLLOW_COLUMNROW_in_atom625);
				value = scriptContext.getCellValue((COLUMNROW7 != null ? COLUMNROW7.getText() : null));

			}
				break;
			case 5:
				// D:\\antlr\\Expr.g:102:11: '(' expr ')'
			{
				match(input, 21, FOLLOW_21_in_atom639);
				pushFollow(FOLLOW_expr_in_atom641);
				expr8 = expr();

				state._fsp--;

				match(input, 22, FOLLOW_22_in_atom643);
				value = expr8;

			}
				break;

			}
		} catch (RecognitionException re) {
			reportError(re);
			recover(input, re);
		} finally {
		}
		return value;
	}

	// $ANTLR end "atom"

	// Delegated rules

	public static final BitSet FOLLOW_multExpr_in_expr68 = new BitSet(new long[] { 0x0000000000000032L });
	public static final BitSet FOLLOW_PLUS_in_expr85 = new BitSet(new long[] { 0x0000000000200E40L });
	public static final BitSet FOLLOW_multExpr_in_expr89 = new BitSet(new long[] { 0x0000000000000032L });
	public static final BitSet FOLLOW_SUB_in_expr106 = new BitSet(new long[] { 0x0000000000200E40L });
	public static final BitSet FOLLOW_multExpr_in_expr110 = new BitSet(new long[] { 0x0000000000000032L });
	public static final BitSet FOLLOW_PLUS_in_expr125 = new BitSet(new long[] { 0x0000000000000100L });
	public static final BitSet FOLLOW_strValue_in_expr130 = new BitSet(new long[] { 0x0000000000000032L });
	public static final BitSet FOLLOW_strValue_in_expr186 = new BitSet(new long[] { 0x0000000000000012L });
	public static final BitSet FOLLOW_PLUS_in_expr210 = new BitSet(new long[] { 0x0000000000200E40L });
	public static final BitSet FOLLOW_multExpr_in_expr214 = new BitSet(new long[] { 0x0000000000000012L });
	public static final BitSet FOLLOW_PLUS_in_expr239 = new BitSet(new long[] { 0x0000000000000100L });
	public static final BitSet FOLLOW_strValue_in_expr243 = new BitSet(new long[] { 0x0000000000000012L });
	public static final BitSet FOLLOW_atom_in_multExpr293 = new BitSet(new long[] { 0x0000000000180002L });
	public static final BitSet FOLLOW_19_in_multExpr312 = new BitSet(new long[] { 0x0000000000200E40L });
	public static final BitSet FOLLOW_atom_in_multExpr316 = new BitSet(new long[] { 0x0000000000180002L });
	public static final BitSet FOLLOW_20_in_multExpr327 = new BitSet(new long[] { 0x0000000000200E40L });
	public static final BitSet FOLLOW_atom_in_multExpr331 = new BitSet(new long[] { 0x0000000000180002L });
	public static final BitSet FOLLOW_FUNCNAME_in_func362 = new BitSet(new long[] { 0x0000000000200000L });
	public static final BitSet FOLLOW_21_in_func364 = new BitSet(new long[] { 0x0000000000600FC0L });
	public static final BitSet FOLLOW_WS_in_func371 = new BitSet(new long[] { 0x0000000000400080L });
	public static final BitSet FOLLOW_args_in_func385 = new BitSet(new long[] { 0x0000000000400000L });
	public static final BitSet FOLLOW_22_in_func394 = new BitSet(new long[] { 0x0000000000000002L });
	public static final BitSet FOLLOW_expr_in_args423 = new BitSet(new long[] { 0x0000000000800002L });
	public static final BitSet FOLLOW_23_in_args443 = new BitSet(new long[] { 0x0000000000600FC0L });
	public static final BitSet FOLLOW_strQuoted_in_args457 = new BitSet(new long[] { 0x0000000000800002L });
	public static final BitSet FOLLOW_expr_in_args480 = new BitSet(new long[] { 0x0000000000800002L });
	public static final BitSet FOLLOW_StringLiteral_in_strValue533 = new BitSet(new long[] { 0x0000000000000002L });
	public static final BitSet FOLLOW_StringLiteral_in_strQuoted555 = new BitSet(new long[] { 0x0000000000000002L });
	public static final BitSet FOLLOW_NumberLiteral_in_atom584 = new BitSet(new long[] { 0x0000000000000002L });
	public static final BitSet FOLLOW_VAR_in_atom597 = new BitSet(new long[] { 0x0000000000000002L });
	public static final BitSet FOLLOW_func_in_atom611 = new BitSet(new long[] { 0x0000000000000002L });
	public static final BitSet FOLLOW_COLUMNROW_in_atom625 = new BitSet(new long[] { 0x0000000000000002L });
	public static final BitSet FOLLOW_21_in_atom639 = new BitSet(new long[] { 0x0000000000600FC0L });
	public static final BitSet FOLLOW_expr_in_atom641 = new BitSet(new long[] { 0x0000000000400000L });
	public static final BitSet FOLLOW_22_in_atom643 = new BitSet(new long[] { 0x0000000000000002L });

}